
url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=' + self.access_token
fp = open('/users/xxxx/pictures/some/xxxx.jpg', 'rb')
content = fp.read()

#方法一
from urllib3 import encode_multipart_formdata  # 主要是引用这个传为数据流
files = {'media': ('image.png', content, 'image/jpeg')}
encode_data = encode_multipart_formdata(files)
headers = {'Content-Type': 'multipart/form-data'}
r = requests.post(url, data=encode_data[0],headers=headers)
print(r.request.headers)
print(r.content)

#方法二
from requests_toolbelt.multipart.encoder import MultipartEncoder
m = MultipartEncoder({'media': ('test1.jpg', content, 'image/jpeg')})
headers = {'Content-Type': 'multipart/form-data'}
r = requests.post(url, data=m,headers=headers)
print(r.request.headers)
print(r.content)